/**
    Copyright (C) 2011  Alexander Vollmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jefb.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//@Aspect
public class LoggerAspect {
	// private static Logger logger =
	// LoggerFactory.getLogger(LoggerAspect.class);

	// @AfterThrowing(pointcut="execution(* org.jefb.service.impl.*.*(..))",
	// throwing="throwable", argNames="joinPoint, throwable")
	// public void loggerAdvice(JoinPoint joinPoint, Throwable throwable) throws
	// Throwable {
	// Class<?> clazz = joinPoint.getTarget().getClass();
	// String name = joinPoint.getSignature().getName();
	// Logger logger = LoggerFactory.getLogger(LoggerAspect.class);
	// String msg = "Exception by executing »"+name+"« on "+clazz;
	// logger.error(msg, throwable);
	// throw throwable;
	// }

	//@Around("execution(* org.jefb.*.*.*(..))")
	public Object aroundAdvice(ProceedingJoinPoint call) throws Throwable {
		try {
			Object retVal = call.proceed();
			return retVal;
		} catch (Exception e) {
			Class<?> clazz = call.getTarget().getClass();
			String name = call.getSignature().getName();
			String msg = "Exception by executing »" + name + "« on " + clazz;
			Logger logger = LoggerFactory.getLogger(clazz);
			logger.error(msg);
			throw e;
		}
	}
}
